package com.xjoyt.pay.master.repository;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;

import com.xjoyt.pay.master.dao.MerchantMoneyRepositoryCustom;
import com.xjoyt.pay.master.po.MerchantMoney;
import com.xjoyt.pay.repository.Repository;
import com.xjoyt.pay.vo.MoneyType;

public interface MerchantMoneyRepository extends Repository<MerchantMoney>, MerchantMoneyRepositoryCustom {

	@Query(" select a.merchant.id, sum(a.money) from MerchantMoney a where a.merchant.id in ?1 group by a.merchant.id")
	List<Object[]> sumByMerchantIdInGroupByMerchantIdIn(List<String> merchantIds);

	@Query(" select a.channel.id, sum(a.money) from MerchantMoney a where a.merchant.id = ?1 group by channel.id")
	List<Object[]> sumByMerchantIdGroupByChannelId(String merchantId);

	// List<MerchantMoney> findAllByNoAndType(String no, String type);

	Page<MerchantMoney> findAllByNoAndType(String no, MoneyType type, Pageable pageable);

	@Query(" select sum(a.money) from MerchantMoney a where a.merchant.id in ?1")
	String sumByMerchantIdInGroupByMerchantIdIn(String merchantId);

}
